package com.rc.saas.mini.service.rc;

import com.rc.saas.mini.mapper.rc.RcMemberGainSettingMapper;
import com.rc.saas.mini.model.rc.RcMemberGainSetting;
import com.rc.saas.mini.model.rc.RcMemberGainSettingExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class RcMemberGainSettingServiceImpl implements RcMemberGainSettingService {
    @Autowired
    private RcMemberGainSettingMapper rcMemberGainSettingMapper;

    @Override
    public RcMemberGainSettingMapper getMapper() {
        return rcMemberGainSettingMapper;
    }

    @Override
    public List<RcMemberGainSetting> listByDefault() {
        RcMemberGainSettingExample example = new RcMemberGainSettingExample();
        example.createCriteria().andStatusEqualTo("0").andIsDefaultEqualTo("1");
        example.setOrderByClause("sort");
        return rcMemberGainSettingMapper.selectByExample(example);

    }

    @Override
    public List<RcMemberGainSetting> listByDefaultWithLevelSub(String levelSub) {
        List<RcMemberGainSetting> list = listByDefault();
        return list.stream().filter(data -> levelSub.equals(data.getLevelSub().trim())).collect(Collectors.toList());
    }

    @Override
    public List<RcMemberGainSetting> listByAllWithLevelSub(String levelSub) {
        RcMemberGainSettingExample example = new RcMemberGainSettingExample();
        example.createCriteria().andStatusEqualTo("0").andLevelSubEqualTo(levelSub);
        example.setOrderByClause("sort");
        return rcMemberGainSettingMapper.selectByExample(example);
    }

    @Override
    public RcMemberGainSetting listBirthDayByLevelSub(String levelSub) {
        RcMemberGainSettingExample example = new RcMemberGainSettingExample();
        example.createCriteria().andStatusEqualTo("0")
                .andLevelSubEqualTo(levelSub)
                .andGainTypeEqualTo("2");

        return rcMemberGainSettingMapper.selectByExample(example).stream().findFirst().orElseGet(() -> null);
    }
}
